import {Map} from 'immutable'
import {CHANGE_TOP_BANNERS,CHANGE_HOT_RECOMMED,CHANGE_NEW_ALBUM,CHANGE_NEWRANKING,CHANGE_UPRANKING,CHANGE_ORIGINRANKING} from './constants'

const defaultState =Map({
    //轮播图
    topBanners:[],
    //热门推荐
    hotRecommend:[],
    //新碟上架
    newAlbum:[],
    //榜单
    upRanking:{},
    newRanking:{},
    originRanking:{}

})
//将action更新的数据拿来改变state里数据
function reducer(state=defaultState,action){
    switch (action.type) {
        case CHANGE_TOP_BANNERS:
            //这种浅拷贝浪费性能和空间此时又有了一种immutable的解决办法
            // immutable的map包裹的生成一个新对象 且会尽量用原节点
            // return {...defaultState,topBanners:action.topBanners}
            //意思是将topBanners数据改成action.topBanners 
            return state.set("topBanners",action.topBanners);
        case CHANGE_HOT_RECOMMED:
            return state.set("hotRecommend",action.hotRecommend)
        case CHANGE_NEW_ALBUM:
            return state.set("newAlbum",action.newAlbum)  
        case CHANGE_UPRANKING:
            return state.set('upRanking',action.upRanking)
        case CHANGE_NEWRANKING:
            return state.set('newRanking',action.newRanking)
        case CHANGE_ORIGINRANKING:
            return state.set('originRanking',action.originRanking)
        default:
            return state
    }
}
export default reducer
